package com.shiguiwu.springmybatis.app.controller;

import com.shiguiwu.springmybatis.app.entity.WorkEnergizeDetail;
import com.shiguiwu.springmybatis.app.service.WorkEnergizeDetailService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (WorkEnergizeDetail)表控制层
 *
 * @author makejava
 * @since 2022-11-24 21:41:45
 */
@RestController
@RequestMapping("workEnergizeDetail")
public class WorkEnergizeDetailController {
    /**
     * 服务对象
     */
    @Resource
    private WorkEnergizeDetailService workEnergizeDetailService;

    /**
     * 分页查询
     *
     * @param workEnergizeDetail 筛选条件
     * @param pageRequest        分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<WorkEnergizeDetail>> queryByPage(WorkEnergizeDetail workEnergizeDetail, PageRequest pageRequest) {
        return ResponseEntity.ok(this.workEnergizeDetailService.queryByPage(workEnergizeDetail, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<WorkEnergizeDetail> queryById(@PathVariable("id") String id) {
        return ResponseEntity.ok(this.workEnergizeDetailService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param workEnergizeDetail 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<WorkEnergizeDetail> add(WorkEnergizeDetail workEnergizeDetail) {
        return ResponseEntity.ok(this.workEnergizeDetailService.insert(workEnergizeDetail));
    }


    /**
     * @api {PUT} /workEnergizeDetail edit
     * @apiVersion 1.0.0
     * @apiGroup WorkEnergizeDetailController
     * @apiName edit
     * @apiDescription 1111
     * @apiParam (请求体) {String} province
     * @apiParam (请求体) {String} city
     * @apiParam (请求体) {String} county
     * @apiParam (请求体) {String} work
     * @apiParam (请求体) {String} orgId
     * @apiParam (请求体) {String} deviceName
     * @apiParam (请求体) {String} egType
     * @apiParam (请求体) {String} ip
     * @apiParam (请求体) {String} macAddress
     * @apiParam (请求体) {String} sn
     * @apiParam (请求体) {String} deviceStatus
     * @apiParam (请求体) {String} equipNetTime
     * @apiParam (请求体) {String} recentOfflineTime
     * @apiParamExample 请求体示例
     * {"equipNetTime":"rYMoO","city":"c","work":"RvRNcYy","ip":"dQ","county":"E70AJmtD","deviceName":"Zysmd7c9","orgId":"Nm","deviceStatus":"Nx","egType":"g44","macAddress":"bQYp","province":"2kl","sn":"WQfnVYLRT","recentOfflineTime":"vHcm"}
     * @apiSuccess (响应结果) {Object} response
     * @apiSuccessExample 响应结果示例
     * null
     */
    @PutMapping
    public ResponseEntity<WorkEnergizeDetail> edit(@RequestBody WorkEnergizeDetail workEnergizeDetail) {
        return ResponseEntity.ok(this.workEnergizeDetailService.update(workEnergizeDetail));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(String id) {
        return ResponseEntity.ok(this.workEnergizeDetailService.deleteById(id));
    }


    @GetMapping("/testOne")
    public ResponseEntity<String> testOne(String id) {
        this.workEnergizeDetailService.testOne();
        return ResponseEntity.ok("aaa");
    }

}

